package com.rf.HelloSpringBoot.Controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 
 * @author linzhengchun
 *
 * 2017年7月19日 下午11:10:31
 */
@RestController
public class HelloPathVariableController {
	
	/**
	 * 处理请求：http://localhost:8080/HelloSpringBoot/helloPathVariable/100
	 * @param id
	 * @return
	 */
	@GetMapping(value = "/helloPathVariable/{id}")
	public String sayHello1 (@PathVariable("id") Integer id) {
		return "Hello, Spring Boot~ Path Variable</br>" + "Got PathVariable id: " + id;
	}
	
	/**
	 * 处理请求：http://localhost:8080/HelloSpringBoot/helloPathVariable?id=100
	 * @param id
	 * @return
	 */
	@PostMapping(value = "/helloPathVariable")
	//public String sayHello2 (@RequestParam("id") Integer id) {
	public String sayHello2 (@RequestParam(value="id", required=false, defaultValue="0") Integer id) {
		return "Hello, Spring Boot~ Path Variable</br>" + "Got RequestParam id: " + id;
	}
}
